﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.MQ
{
    /// <summary>
    /// 消息中介路由间的通讯通道
    /// </summary>
    public interface IChannel
    {
        /// <summary>
        /// 源
        /// </summary>
        IBinding Source
        {
            get;
        }

        /// <summary>
        /// 目标
        /// </summary>
        IBinding Destination
        {
            get;
        }

        /// <summary>
        /// 连接建立事件
        /// </summary>
        event ChannelConnectionEstablishedEventHandler ConnectionEstablished;

        /// <summary>
        /// 连接关闭事件
        /// </summary>
        event ChannelConnectionClosedEventHandler ConnectionClosed;

        /// <summary>
        /// 数据到达事件
        /// </summary>
        event ChannelDataReceivedEventHandler DataReceived;

        /// <summary>
        /// 推送数据
        /// </summary>
        /// <param name="buffer"></param>
        void WriteBytes(byte[] buffer);

        /// <summary>
        /// 断开连接
        /// </summary>
        void Disconnect();
    }

    public delegate void ChannelDataReceivedEventHandler(IBinding sourc,IBinding destination, Byte[] buffer);
    public delegate void ChannelConnectionEstablishedEventHandler(IBinding source, IBinding destination);
    public delegate void ChannelConnectionClosedEventHandler(IBinding source, IBinding destination);
}
